package ${package_controller};
import ${package_pojo}.${Table};
import ${package_service}.${Table}Service;
import com.github.pagehelper.PageInfo;
import com.util.Result;
<#if swagger==true>import io.swagger.annotations.*;</#if>
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @ClassName: ${Table}Controller
 * @description: ${Table} 控制层接口定义类
 * @author: 李东
 * @Date: 2020-7-20
 */
<#if swagger==true>@Api(value = "${Table}Controller")</#if>
@Slf4j
@RestController
@RequestMapping("/${table}")
@CrossOrigin
public class ${Table}Controller {

    @Autowired
    private ${Table}Service ${table}Service;

    /***
     * ${Table}分页条件搜索实现
     * @param ${table}
     * @param page
     * @param size
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${Table}条件分页查询",notes = "分页条件查询${Table}方法详情",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    </#if>
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) <#if swagger==true>@ApiParam(name = "${Table}对象",value = "传入JSON数据",required = false)</#if> ${Table} ${table}, @PathVariable  int page, @PathVariable  int size){
        log.info("${Table}Controller findPage params , ${table} : {} , page : {} , size : {}",${table},page,size);
        //调用${Table}Service实现分页条件查询${Table}
        PageInfo<${Table}> pageInfo = ${table}Service.findPage(${table}, page, size);
        return Result.buildSuccess("查询成功！", pageInfo);
    }

    /***
     * ${Table}分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${Table}分页查询",notes = "分页查询${Table}方法详情",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    </#if>
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        log.info("${Table}Controller findPage params , page : {} , size : {}",page,size);
        //调用${Table}Service实现分页查询${Table}
        PageInfo<${Table}> pageInfo = ${table}Service.findPage(page, size);
        return Result.buildSuccess("查询成功！", pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param ${table}
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${Table}条件查询",notes = "条件查询${Table}方法详情",tags = {"${Table}Controller"})
    </#if>
    @PostMapping(value = "/search" )
    public Result<List<${Table}>> findList(@RequestBody(required = false) <#if swagger==true>@ApiParam(name = "${Table}对象",value = "传入JSON数据",required = false)</#if> ${Table} ${table}){
        log.info("${Table}Controller findList params , ${table} : {} ",${table});
        //调用${Table}Service实现条件查询${Table}
        List<${Table}> list = ${table}Service.findList(${table});
        return Result.buildSuccess("查询成功！", list);
    }

    /***
     * 根据主键删除品牌数据
     * @param <#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${Table}根据主键<#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>删除",notes = "根据主键删除${Table}方法详情",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            <#list primaryKeys as pr>
                @ApiImplicitParam(paramType = "path", name ="${pr.name}", value = "主键", required = true, dataType = "${pr.type}")<#if pr_has_next>,</#if>
            </#list>
    })
    </#if>
    @DeleteMapping(value = "<#list primaryKeys as pr>/{${pr.name}}</#list>")
    public Result delete(<#list primaryKeys as pr>@PathVariable("${pr.name}") ${pr.type} ${pr.name}<#if pr_has_next>,</#if></#list>){
        log.info("${Table}Controller delete params , <#list primaryKeys as pr>  ${pr.name} : {} <#if pr_has_next>,</#if> </#list> ",<#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>);
        //调用${Table}Service实现根据主键删除
        ${table}Service.delete(<#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>);
        return Result.buildSuccess("删除成功！");
    }

    /***
     * 修改${Table}数据
     * @param ${table}
     * @param <#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${Table}根据<#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>修改",notes = "根据ID修改${Table}方法详情",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            <#list primaryKeys as pr>
            @ApiImplicitParam(paramType = "path", name ="${pr.name}", value = "主键", required = true, dataType = "${pr.type}")<#if pr_has_next>,</#if>
            </#list>
     })
    </#if>
    @PutMapping(value="<#list primaryKeys as pr>/{${pr.name}}</#list>")
    public Result update(@RequestBody <#if swagger==true>@ApiParam(name = "${Table}对象",value = "传入JSON数据",required = false)</#if> ${Table} ${table},<#list primaryKeys as pr>@PathVariable("${pr.name}") ${pr.type} ${pr.name}<#if pr_has_next>,</#if></#list>){
        log.info("${Table}Controller update params ,  ${table} : {},<#list primaryKeys as pr>  ${pr.name} : {} <#if pr_has_next>,</#if> </#list> ",${table},<#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>);
        //设置主键值
        <#list primaryKeys as pr>
        ${table}.${pr.method}(${pr.name});
        </#list>
        //调用${Table}Service实现修改${Table}
        ${table}Service.update(${table});
        return Result.buildSuccess("修改成功！");
    }

    /***
     * 新增${Table}数据
     * @param ${table}
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${Table}添加",notes = "添加${Table}方法详情",tags = {"${Table}Controller"})
    </#if>
    @PostMapping
    public Result add(@RequestBody  <#if swagger==true>@ApiParam(name = "${Table}对象",value = "传入JSON数据",required = true)</#if> ${Table} ${table}){
        log.info("${Table}Controller add params , ${table} : {}",${table});
        //调用${Table}Service实现添加${Table}
        ${table}Service.add(${table});
        return Result.buildSuccess("添加成功！");
    }

    /***
     * 根据ID查询${Table}数据
     * @param <#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${Table}根据<#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>查询",notes = "根据ID查询${Table}方法详情",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            <#list primaryKeys as pr>
            @ApiImplicitParam(paramType = "path", name ="${pr.name}", value = "主键", required = true, dataType = "${pr.type}")<#if pr_has_next>,</#if>
            </#list>
            })
    </#if>
    @GetMapping("<#list primaryKeys as pr>/{${pr.name}}</#list>")
    public Result<${Table}> findById(<#list primaryKeys as pr>@PathVariable("${pr.name}") ${pr.type} ${pr.name}<#if pr_has_next>,</#if></#list>){
        log.info("${Table}Controller findById params , <#list primaryKeys as pr>  ${pr.name} : {} <#if pr_has_next>,</#if> </#list> ",<#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>);
        //调用${Table}Service实现根据主键查询${Table}
        ${Table} ${table} = ${table}Service.findById(<#list primaryKeys as pr>${pr.name}<#if pr_has_next>,</#if></#list>);
        return Result.buildSuccess("查询成功！",${table});
    }

    /***
     * 查询${Table}全部数据
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "查询所有${Table}",notes = "查询所${Table}有方法详情",tags = {"${Table}Controller"})
    </#if>
    @GetMapping
    public Result<List<${Table}>> findAll(){
        //调用${Table}Service实现查询所有${Table}
        List<${Table}> list = ${table}Service.findAll();
        return Result.buildSuccess("查询成功！",list);
    }
}
